<template>
	<view class="container-main" :style="{
		     '--top-bar-height':mp.topBarHeight + 'px',
	         '--safe-area-bottom':mp.systemInfo.safeAreaInsets.bottom + 'px'}">
		<view class="container-main-top"></view>
		<!-- #ifdef MP-WEIXIN -->
		<go-back>观看记录</go-back>
		<!-- #endif -->
		<!-- 推荐 -->
		<view class="section section-recommend" v-if="browseList.loading">
			<view class="recommend">
				<view class="recommend-list" style="width: 100%">
					<view class="recommend-item" v-for="(item,index) in browseList.list" :key="item.skitId" @tap.stop.prevent="onAllVideo(item)">
						<view class="recommend-image" :style="{
							backgroundImage: 'linear-gradient(180deg,transparent 70%,#000), url(' + item.coverPictureUrl + ')',
							backgroundRepeat: 'no-repeat',
							backgroundSize: 'cover',
							backgroundPosition: 'center center'}">
							<view class="pursue">{{item.bingeWatchNum | bingeWatch}}人再追</view>
						</view>
						<view class="scroll-view-item-right">
							<view class="name">{{item.skitName}}</view>
							<view class="time">观看至{{item.episodeName}}</view>
						</view>
					</view>
				</view>
				<view v-show="browseList.loading && browseList.list.length <= 0">
					<empty fixed></empty>
				</view>
				<view v-show="load.loading">
					<uv-load-more :status="load.status" :loading-text="load.loadingText" :nomore-text="load.nomoreText" :line="load.status == 'nomore'" />
				</view>
			</view>
		</view>
	</view>
</template>


<script>
	const app = getApp();
	import mp from "@/mixins/mp.js";
	import empty from '@/components/empty/empty.vue';
	import goBack from '@/components/back/back.vue';
	import { getMyBrowse } from '@/common/api';
	export default {
		mixins: [mp],
		components: {
			empty,
			goBack
		},
		data() {
			return {
				browseList: {
					list: [],
					hasMore: false,
					loading: false,
					page: 1,
				},
				load: {
					loading: false,
					status: 'loading',
					loadingText: '努力加载中',
					nomoreText: '没有更多了'
				},
			}
		},
		onLoad(option) {
			this.getPageData();
		},
		onShow() {},
		onHide() {},
		/**
		 * 触底
		 */
		onReachBottom() {
			if (this.browseList.hasMore && this.browseList.loading) {
				this.load.loading = true
				this.requestMyBrowse()
			}
		},
		watch: {},
		filters: {
			bingeWatch(val) {
				// let watchNum = Number(val) * random(10000, 99999)
				if (val == 0) {
					return (random(100000, 999999) / 10000).toFixed(1) + '万'
				} else {
					return (val / 10000).toFixed(1) + '万'
				}
			}
		},

		methods: {
			// 加载页面数据
			getPageData: function(callback) {
				Promise.all([this.requestMyBrowse()]).then(() => {
					callback && callback()
				}).catch(() => {
					callback && callback()
				});
			},
			requestMyBrowse() {
				return new Promise((resolve, reject) => {
					let params = { pageNo: this.browseList.page, pageSize: 6 };
					getMyBrowse(params).then((result) => {
						let total = result.total;
						let data = result.list;
						let { page, list, hasMore } = this.browseList;
						if (1 == page) {
							list.length = 0;
						}
						list = [...list, ...data];
						hasMore = total > list.length;
						if (hasMore) {
							page++;
							this.load.loading = false;
						} else {
							this.load.status = 'nomore';
							this.load.loading = list.length > 4;
						}
						resolve({ data: data.length, hasMore });
						this.browseList.page = page;
						this.browseList.list = list;
						this.browseList.hasMore = hasMore;
						this.browseList.loading = true;
					}).catch((err) => {
						this.browseList.loading = true;
						reject();
					});
				});
			},
			onAllVideo(item) {
				let id = item.skitId ? item.skitId : item.id
				uni.navigateTo({
					url: '/page_account/video/video?ablum_id=' + id  + '&tt_album_id=' + item.thirdSkitId + '&tt_episode_id=' + item.thirdEpisodeId
				})
			},
		}
	}
</script>


<style lang="scss">
	page {
		/* #ifdef MP-WEIXIN */
		background: #000;
		/* #endif */
		// background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/peng-jc/new_bg.png');
		// background-repeat: no-repeat;
		// background-size: 100% 1071rpx;
		// background-position: 0 0;
	}

	.container-main {
		box-sizing: border-box;
		padding-top: calc(var(--top-bar-height) + 24rpx);
		padding-bottom: calc(var(--safe-area-bottom) + 24rpx);

		.container-main-top {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			width: 100%;
			height: calc(var(--top-bar-height) + 24rpx);
			background: #000;
			// background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/peng-jc/new_bg.png');
			// background-repeat: no-repeat;
			// background-size: 100% 1071rpx;
			// background-position: 0 0;
		}


		.section {
			margin-bottom: 64rpx;

			.title {
				font-weight: 900;
				font-size: 36rpx;
				color: #FFFFFF;
				line-height: 50rpx;
				box-sizing: border-box;
				padding-left: 24rpx;
				margin-bottom: 24rpx;
			}

			.recent-browse {
				.scroll-view_H {
					white-space: nowrap;

					.scroll-view-item {
						width: 398rpx;
						height: 174rpx;
						display: inline-block;
						border-radius: 20rpx;
						border: 1rpx solid transparent;
						background-clip: padding-box, border-box;
						background-origin: padding-box, border-box;
						background-image: linear-gradient(#160F15, #160F15), linear-gradient(137deg, rgba(255, 255, 255, 0.31), rgba(255, 255, 255, 0.1));
						backdrop-filter: blur(8px);
						margin-left: 16rpx;
						box-sizing: border-box;
						padding: 16rpx;
						white-space: nowrap;

						&:first-child {
							margin-left: 24rpx;
						}

						&:last-child {
							margin-right: 24rpx;
						}

						image {
							width: 118rpx;
							height: 142rpx;
							border-radius: 20rpx;
							margin-right: 16rpx;
							display: inline-block;
							vertical-align: middle;
						}

						.scroll-view-item-right {
							display: inline-block;
							vertical-align: middle;

							.name {
								font-weight: 600;
								font-size: 28rpx;
								color: #FFFFFF;
								line-height: 40rpx;
								margin-bottom: 20rpx;
								width: calc(398rpx - 118rpx - 16rpx - 16rpx);
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}

							.time {
								font-weight: 400;
								font-size: 24rpx;
								color: #A09D9E;
								line-height: 33rpx;
							}
						}
					}
				}
			}
		}

		.section-recommend {
			margin-bottom: 0;

			.recommend {
				box-sizing: border-box;
				padding: 0 24rpx;

				.recommend-list {
					display: grid;
					grid-template-columns: calc(50% - 11rpx) calc(50% - 11rpx);
					column-gap: 22rpx;
					row-gap: 40rpx;
					width: 100%;

					.recommend-item {

						.recommend-image {
							width: 100%;
							height: 408rpx;
							border-radius: 20rpx;
							position: relative;

							.pursue {
								position: absolute;
								right: 16rpx;
								bottom: 16rpx;
								font-weight: 400;
								font-size: 22rpx;
								color: #FFFFFF;
								line-height: 30rpx;
							}
						}

						.scroll-view-item-right {
							margin-top: 20rpx;

							.name {
								font-weight: 400;
								font-size: 28rpx;
								color: #FFFFFF;
								line-height: 40rpx;
								margin-bottom: 8rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}

							.time {
								font-weight: 400;
								font-size: 24rpx;
								color: #A09D9E;
								line-height: 33rpx;
							}
						}
					}
				}
			}

		}
	}
</style>